//
//  HMTabBarController.m
//  UI进阶-21-网易彩票
//
//  Created by 柯平常 on 16/4/3.
//  Copyright © 2016年 柯平常. All rights reserved.
//

#import "SNMYNavigationController.h"
#import "SNMYLSViewController.h"
#import "HomeOrganizationalViewController.h"
#import "HMTabBarController.h"
#import "HMNavigationController.h"
#import "HomeLSViewController.h"
#import "FinanceLSViewController.h"
#import "MyZhuoXinLSViewController.h"
#import "MyZhuoXinLSViewControllerNMDh.h"
#import "MyZhuoXinLSViewControllerNMNc.h"
#import "HomeLSViewControllerSecond.h"

//小农
#import "MyZhuoXinLSViewControllerNM.h"
#import "ManagerViewController.h"


@interface HMTabBarController ()

@end

@implementation HMTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

}
-(void)setUSERTYPE:(NSString *)USERTYPE{
    _USERTYPE = USERTYPE;
    [self setupChildViewControllers];
}

#pragma mark - 加载子控制器
-(void)setupChildViewControllers{
    NSLog(@"self.USERTYPE.integerValue = %ld",self.USERTYPE.integerValue);
    
    
    if (self.USERTYPE.integerValue == 4) {
        
        ManagerViewController *manVc = [[ManagerViewController alloc]init];
        [UIApplication sharedApplication].keyWindow.rootViewController = [[SNMYNavigationController alloc]initWithRootViewController:manVc];
        
        return;
    }
    
    
    
    /** icon 1 */
    switch (self.USERTYPE.integerValue) {
        case 1:
            [self sn_addChildController:@"" normalImageName:@"menu_ico1_n" selectedImageName:@"menu_ico1_p" viewController:[[HomeLSViewControllerSecond alloc] init]];
            break;
        case 2:
            [self sn_addChildController:@"" normalImageName:@"menu_ico1_n" selectedImageName:@"menu_ico1_p" viewController:[[HomeLSViewControllerSecond alloc] init]];
            break;
        case 3:
            [self sn_addChildController:@"" normalImageName:@"menu_ico1_n" selectedImageName:@"menu_ico1_p" viewController:[[HomeLSViewControllerSecond alloc] init]];
            break;
//        case 4:
//            [self sn_addChildController:@"" normalImageName:@"menu_ico1_n" selectedImageName:@"menu_ico1_p" viewController:[[HomeLSViewControllerSecond alloc] init]];
//            break;
        case 5:
            [self sn_addChildController:@"" normalImageName:@"menu_ico1_n" selectedImageName:@"menu_ico1_p" viewController:[[HomeLSViewControllerSecond alloc] init]];
            break;
        case 6:// 组织业务代表
            [self sn_addChildController:@"" normalImageName:@"menu_ico1_n" selectedImageName:@"menu_ico1_p" viewController:[[HomeOrganizationalViewController alloc] init]];
            break;
        case 7:// 组织业务代表
            [self sn_addChildController:@"" normalImageName:@"menu_ico1_n" selectedImageName:@"menu_ico1_p" viewController:[[HomeOrganizationalViewController alloc] init]];
            break;
        default:
            break;
    }
    
    /** icon 2 */
    [self sn_addChildController:@"" normalImageName:@"menu_ico2_n" selectedImageName:@"menu_ico2_p" viewController:[[FinanceLSViewController alloc] initWithNibName:@"FinanceLSViewController" bundle:nil]];
    
    
    /** icon 3 */
    switch (self.USERTYPE.integerValue) {
        case 6:
        case 7:
            //业务代表
//            [self addChildController:@"" normalImageName:@"menu_ico3_n" selectedImageName:@"menu_ico3_p" viewController:[[MyZhuoXinLSViewController alloc] initWithNibName:@"MyZhuoXinLSViewController" bundle:nil]];
            
            [self sn_addChildController:@"" normalImageName:@"menu_ico3_n" selectedImageName:@"menu_ico3_p" viewController:[[SNMYLSViewController alloc] init]];
            
            break;
        case 1:
        case 2:
        case 12:
            //小农
            [self sn_addChildController:@"" normalImageName:@"menu_ico3_n" selectedImageName:@"menu_ico3_p" viewController:[[SNMYLSViewController alloc] init]];
            break;
        case 3:
            //大户
            [self sn_addChildController:@"" normalImageName:@"menu_ico3_n" selectedImageName:@"menu_ico3_p" viewController:[[SNMYLSViewController alloc] init]];
            break;
        case 5:
            //农场
            [self sn_addChildController:@"" normalImageName:@"menu_ico3_n" selectedImageName:@"menu_ico3_p" viewController:[[SNMYLSViewController alloc] init]];
            break;
        default:
            break;
    }
}


//-(void)addChildController:(NSString *)title normalImageName:(NSString *)imageName selectedImageName:(NSString *)selImageName viewController:(UIViewController *)viewController{
//    
//    viewController.title = title;
//    
//    NSMutableDictionary *textAttrs=[NSMutableDictionary dictionary];
//    textAttrs[NSForegroundColorAttributeName]=[UIColor orangeColor];
//    [viewController.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateSelected];
//    
//    
//    viewController.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    
//    viewController.tabBarItem.selectedImage = [[UIImage imageNamed:selImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    
//    viewController.tabBarItem.imageInsets = UIEdgeInsetsMake(6.5, 0, -6.5, 0);;
//    
//    [self addChildViewController:[[HMNavigationController alloc]initWithRootViewController:viewController]];
//}
-(void)sn_addChildController:(NSString *)title normalImageName:(NSString *)imageName selectedImageName:(NSString *)selImageName viewController:(UIViewController *)viewController{
    
    viewController.title = title;
    
    NSMutableDictionary *textAttrs=[NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName]=[UIColor orangeColor];
    [viewController.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateSelected];
    
    
    viewController.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    viewController.tabBarItem.selectedImage = [[UIImage imageNamed:selImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //    UIEdgeInsets insets = UIEdgeInsetsMake(16, 0, -16, 0);
    viewController.tabBarItem.imageInsets = UIEdgeInsetsMake(6.5, 0, -6.5, 0);;
    //    [self setupChildViewControllers];
    
    
    [self addChildViewController:[[SNMYNavigationController alloc]initWithRootViewController:viewController]];
}

@end
